define([ "app", "jquery", "js/directives/DatetimePicker", "js/services/MessageBox", "js/services/MuseService"], function(app) {

    var deps = [ "$scope", "$state", "$modal", "MessageBox", "$modalInstance", "MuseService","mainTitle"];

    function controller($scope, $state, $modal, MessageBox, $modalInstance, MuseService,mainTitle) {
        // 参数对象列表, 显示记录数, 每页记录数.
        $scope.objList = [];

        // 初始化从firstPageSize到lastPageSize条数据值
        $scope.firstPageSize = 0;
        $scope.lastPageSize = 0;
        $scope.columnList = [];

        // 获取列表函数定义.
        $scope.getObjList = function() {
            MuseService.postObj("owner/getAllOwners", {}).success(
                function(data, status, headers, config) {
                    if (data.code == 0) {
                        $scope.objList = data.data;
                    }
                });
        };

        // 获取列表.
        $scope.getObjList();
        //确定
        $scope.ok = function () {
            var selObjList = $scope.selObjList;

            /*
             * 已处理多选中切换问题   以及选择问题
             */

            var objIds = MuseService.getMapKeyArray(selObjList);
            if (!objIds.length) {
                MessageBox.error("请至少选择一条记录.");
                return;
            }

            if (objIds.length>1) {
                MessageBox.error("只能选择一条记录,当前已选择数量:"+objIds.length);
                return;
            }

            $modalInstance.close(MuseService.getMapValueArray(selObjList));
        };

        $scope.cancel = function () {
            $modalInstance.close();
        };

        // 全选--开始
        $scope.selObjList = {}; // 选中的参数集合
        $scope.isSelectAll = false;
        $scope.toggleAll = function() {
            var rst = MuseService.toggleAll($scope.objList, $scope.selObjList, $scope.isSelectAll);
            $scope.selObjList = rst.selObjList;
            $scope.isSelectAll = rst.isSelectAll;
        };
        // 选择复选框，改变数组中元素，与checkbox相关
        $scope.toggleSingle = function(obj) {
            $scope.selObjList = MuseService.toggleSingle($scope.selObjList, obj);
        };
        // 全选--结束

    } // end function controller.

    controller.$inject = deps;
    app.lazy.controller("SelOwnerController", controller);
});
